home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfb8bit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  4.5 KB  |  200 lines

  1. /*
  2.  * cfb8bit.c
  3.  *
  4.  * 8 bit color frame buffer utility routines
  5.  */
  6.  
  7. /* $XConsortium: cfb8bit.c,v 1.3 89/09/19 15:36:32 keith Exp $ */
  8.  
  9. #include    "X.h"
  10. #include    "Xmd.h"
  11. #include    "Xproto.h"
  12. #include    "fontstruct.h"
  13. #include    "dixfontstr.h"
  14. #include    "gcstruct.h"
  15. #include    "windowstr.h"
  16. #include    "scrnintstr.h"
  17. #include    "pixmapstr.h"
  18. #include    "regionstr.h"
  19. #include    "cfb.h"
  20. #include    "cfbmskbits.h"
  21. #include    "cfb8bit.h"
  22.  
  23. #if (PPW == 4)
  24.  
  25. unsigned long cfb8PixelMasks[16] = {
  26.     0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
  27.     0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
  28.     0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
  29.     0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff,
  30. };
  31.  
  32. unsigned long    cfb8Pixels[16];
  33. unsigned long    cfb8Pixelsfg, cfb8Pixelsbg;
  34.  
  35. void
  36. cfb8SetPixels (fg, bg)
  37. unsigned long    fg, bg;
  38. {
  39.     unsigned long   filledFg, filledBg;
  40.     int    s;
  41.     unsigned long   c;
  42.  
  43.     cfb8Pixelsfg = fg & 0xff;
  44.     cfb8Pixelsbg = bg & 0xff;
  45.     filledFg = PFILL(cfb8Pixelsfg);
  46.     filledBg = PFILL(cfb8Pixelsbg);
  47.     /*
  48.      * create the appropriate pixel-fill bits for current
  49.      * foreground
  50.      */
  51.     for (s = 0; s < 16; s++)
  52.     {
  53.     c = 0;
  54.     if (s & 1)
  55.         c |= 0xff;
  56.     if (s & 2)
  57.         c |= 0xff00;
  58.      if (s & 4)
  59.         c |= 0xff0000;
  60.      if (s & 8)
  61.         c |= 0xff000000;
  62.     cfb8Pixels[s] = (c & filledFg) | (~c & filledBg);
  63.     }
  64. }
  65.  
  66. /*
  67.  * a grungy little routine.  This computes clip masks
  68.  * for partial character blts.  Returns rgnOUT if the
  69.  * entire character is clipped; returns rgnIN if the entire
  70.  * character is unclipped; returns rgnPART if a portion of
  71.  * the character is visible.  Computes clip masks for each
  72.  * longword of the character -- and those with the
  73.  * contents of the glyph to compute the visible bits.
  74.  */
  75.  
  76. #if (BITMAP_BIT_ORDER == MSBFirst)
  77. unsigned long    cfb8BitLenMasks[32] = {
  78.     0xffffffff, 0x7fffffff, 0x3fffffff, 0x1fffffff,
  79.     0x0fffffff, 0x07ffffff, 0x03ffffff, 0x01ffffff,
  80.     0x00ffffff, 0x007fffff, 0x003fffff, 0x001fffff,
  81.     0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff,
  82.     0x0000ffff, 0x00007fff, 0x00003fff, 0x00001fff,
  83.     0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
  84.     0x000000ff, 0x0000007f, 0x0000003f, 0x0000001f,
  85.     0x0000000f, 0x00000007, 0x00000003, 0x00000001,
  86. };
  87. #else
  88. unsigned long cfb8BitLenMasks[32] = {
  89.     0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
  90.     0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
  91.     0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
  92.     0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
  93.     0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
  94.     0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
  95.     0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
  96.     0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
  97. };
  98. #endif
  99.  
  100. int
  101. cfb8ComputeClipMasks32 (pBox, numRects, x, y, w, h, clips)
  102.     BoxPtr    pBox;
  103.     int        numRects;
  104.     int        x, y, w, h;
  105.     unsigned long   *clips;
  106. {
  107.     int        yBand, yBandBot;
  108.     int        ch;
  109.     unsigned long        clip;
  110.     int        partIN = FALSE, partOUT = FALSE;
  111.     int        result;
  112.  
  113.     if (numRects == 0)
  114.     return rgnOUT;
  115.     while (numRects && pBox->y2 <= y)
  116.     {
  117.     --numRects;
  118.     ++pBox;
  119.     }
  120.     if (!numRects || pBox->y1 >= y + h)
  121.     return rgnOUT;
  122.     yBand = pBox->y1;
  123.     while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
  124.     {
  125.     --numRects;
  126.     ++pBox;
  127.     }
  128.     if (!numRects || pBox->y1 >= y + h)
  129.     return rgnOUT;
  130.     if (numRects &&
  131.     x >= pBox->x1 &&
  132.     x + w <= pBox->x2 &&
  133.     y >= pBox->y1 &&
  134.     y + h <= pBox->y2)
  135.     {
  136.     return rgnIN;
  137.     }
  138.     ch = 0;
  139.     while (ch < h && y + ch < pBox->y1)
  140.     {
  141.     partOUT = TRUE;
  142.     clips[ch++] = 0;
  143.     }
  144.     while (numRects && pBox->y1 < y + h)
  145.     {
  146.     yBand = pBox->y1;
  147.     yBandBot = pBox->y2;
  148.         while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
  149.         {
  150.         --numRects;
  151.         ++pBox;
  152.         }
  153.         if (!numRects)
  154.         break;
  155.     clip = 0;
  156.         while (numRects && pBox->y1 == yBand && pBox->x1 < x + w)
  157.         {
  158.         if (x < pBox->x1)
  159.         if (pBox->x2 < x + w)
  160.             clip |= cfb8BitLenMasks[pBox->x1 - x] & ~cfb8BitLenMasks[pBox->x2 - x];
  161.         else
  162.             clip |= cfb8BitLenMasks[pBox->x1 - x];
  163.          else
  164.         if (pBox->x2 < x + w)
  165.             clip |= ~cfb8BitLenMasks[pBox->x2 - x];
  166.         else
  167.             clip = ~0;
  168.         --numRects;
  169.         ++pBox;
  170.         }
  171.     if (clip != 0)
  172.         partIN = TRUE;
  173.     if (clip != ~0)
  174.         partOUT = TRUE;
  175.     while (ch < h && y + ch < yBandBot)
  176.         clips[ch++] = clip;
  177.     while (numRects && pBox->y1 == yBand)
  178.     {
  179.         --numRects;
  180.         ++pBox;
  181.     }
  182.     }
  183.     while (ch < h)
  184.     {
  185.     partOUT = TRUE;
  186.     clips[ch++] = 0;
  187.     }
  188.     result = rgnOUT;
  189.     if (partIN)
  190.     {
  191.     if (partOUT)
  192.         result = rgnPART;
  193.     else
  194.         result = rgnIN;
  195.     }
  196.     return result;
  197. }
  198.  
  199. #endif /* PPW == 4 */
  200.